/**
 * Created by LiYang on 16-9-27 下午2:07.
 *
 */
package com.example.db.common;

import com.example.db.utils.ObjectUtil;

import java.util.HashMap;


public class EntityHashMap extends HashMap<String, Object> implements BasicSerializable<Long> {
    public static final long serialVersionUID = 42L;
    private long id;

    public String getString(String key) {
        return (String) super.get(key);
    }

    public Number getNumber(String key) {
        return (Number) super.get(key);
    }

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    public byte[] getBytes(String key) {
        String res = getString(key);
        if (ObjectUtil.isEmpty(res)) {
            return new byte[0];
        }
        return res.getBytes(SaizConstant.DEF_ENCODE);
    }

    public char[] getChars(String key) {
        String res = getString(key);
        if (ObjectUtil.isEmpty(res)) {
            return new char[0];
        }
        return res.toCharArray();
    }

    public short getShort(String key) {
        Number res = getNumber(key);
        if (res == null) {
            return Short.MIN_VALUE;
        }
        return res.shortValue();
    }

    public int getInt(String key) {
        Number res = getNumber(key);
        if (res == null) {
            return Integer.MIN_VALUE;
        }
        return res.intValue();
    }

    public long getLong(String key) {
        Number res = getNumber(key);
        if (res == null) {
            return Long.MIN_VALUE;
        }
        return res.longValue();
    }

    public float getFloat(String key) {
        Number res = getNumber(key);
        if (res == null) {
            return Float.MIN_VALUE;
        }
        return res.floatValue();
    }

    public double getDouble(String key) {
        Number res = getNumber(key);
        if (res == null) {
            return Double.MIN_VALUE;
        }
        return res.doubleValue();
    }

    public boolean getBoolean(String key) {
        String res = getString(key);
        if (res == null || "".equals(res)) {
            return false;
        }
        return Boolean.valueOf(res);
    }
}
